<?php
class Api_EnsayesController extends App_Controller {	
	private $_model;

    public function init() {
        $this->_model = new Api_Model_Ensayes();

        parent::init();
    }
    
    public function getAction() {
        $id = $this->_request->getParam('id');
        echo json_encode($this->_model->getEnsaye($id));
	}

	public function postAction () {
		$ensaye = json_decode($this->_request->getRawBody(), true);

		if (!$this->_model->addEnsaye($ensaye)) {
            $this->_response->setHttpResponseCode(500);
        }
	}

	public function putAction () {
		$id = $this->_request->getParam('id');
		$ensaye = json_decode($this->_request->getRawBody(), true);

        if (!$this->_model->editEnsaye($id, $ensaye)) {
            $this->_response->setHttpResponseCode(500); 
        }
	}
}
